package com.jinxin.platform.cdacscontrolmgr.controller;

import com.jinxin.platform.base.api.annotation.APCOSApi;
import com.jinxin.platform.base.api.annotation.APCOSApiOperation;
import com.jinxin.platform.base.api.constant.APCOSApiConstans;
import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdacscontrolmgr.bean.CdacscontrolmgrOwner;
import com.jinxin.platform.cdacscontrolmgr.service.ICdacscontrolkmgrOwnerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2021-09-22
 * @Author: Lingnan
 **/
@APCOSApi(value = "门禁业主接口", developers = {"lingnan"}, description = "门禁业主接口")
@RestController
@RequestMapping("/cdacscontrolmgr/cdacscontrolmgrOwner")
@Slf4j
public class CdacscontrolmgrOwnerController {
    @Autowired
    private ICdacscontrolkmgrOwnerService cdacscontrolkmgrOwnerService;

    @APCOSApiOperation(value = "分页查询业主", developers = {"lingnan"}, description = "分页查询业主",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @GetMapping("/list")
    public Map<String,Object> list(@RequestParam int page, @RequestParam int limit,
                                   @RequestParam(name = "projectId")String projectId,String roomNo,
                                   String name,String phone){
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("code",0);
        if(StringUtils.isEmpty(projectId)){
            resultMap.put("msg","项目id为空");
            resultMap.put("data", null);
            return resultMap;
        }
        HashMap param = new HashMap();
        param.put("page", page);
        param.put("limit", limit);
        param.put("projectId", projectId);
        param.put("roomNo", roomNo);
        param.put("name", name);
        param.put("phone", phone);
        resultMap.put("count", cdacscontrolkmgrOwnerService.listPageCount(param));
        resultMap.put("data", cdacscontrolkmgrOwnerService.list(param));
        return resultMap;
    }

    @APCOSApiOperation(value = "保存或更新业主", developers = {"lingnan"}, description = "保存或更新业主",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @PostMapping("/saveOrUpdate")
    public JsonResult saveOrUpdate(CdacscontrolmgrOwner record, MultipartFile file){
        return cdacscontrolkmgrOwnerService.saveOrUpdate(record,file);
    }

    @APCOSApiOperation(value = "删除业主", developers = {"lingnan"}, description = "删除业主",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @GetMapping("/delete")
    public JsonResult delete(String id){
        return cdacscontrolkmgrOwnerService.delete(id);
    }
}
